package com.teach.config;

import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.github.pagehelper.PageInterceptor;
import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import com.teach.commons.Id;

import lombok.extern.slf4j.Slf4j;

@Configuration
@Slf4j
public class BeansConfig {
	
	@Autowired
	private ConfigProperties config;
	
	
	@Bean
	@Primary
	public Id id() {
		log.debug("ConfigProperties={}",config);
		return new Id(config.id.workerId,config.id.datacenterId);
	}
	
	@Bean
	public Producer producer() {
		DefaultKaptcha kaptcha = new DefaultKaptcha();
		kaptcha.setConfig(new Config(config.kaptchaProperties));
		return kaptcha;
	}
	
	@Bean
	public PageInterceptor pageInterceptor() {
		PageInterceptor p = new PageInterceptor();
		Properties properties = new Properties();
		properties.setProperty("helperDialect", "mysql");
		p.setProperties(properties);
		return p;
	}

}
